<?php
require_once 'tools/http/HTTP_REQUEST.php';
require_once 'tools/db/DbUtils.php';
require_once 'tools/service/tools.php';
require_once 'tools/db/queries.php';
if(Config::team){
	include 'pages/header/result_header.php';
}
$obj_utils=new DbUtils();
$obj_utils->connect();
$queryKey=HTTP_RESQUEST::get('query');
$course=HTTP_RESQUEST::get('course');
if($queryKey=="general"){
	$course=$obj_utils->getCourse();	
}
$courseToShow=$course;
if($queryKey=="challenge"){
	$courseToShow="ALL CHALLENGE";
}

$tool=new Tool($obj_utils);
$query=getQueryForKey($queryKey,$course);
$tabRequest=$obj_utils->executeQuery($query);
?>
<h1>Resultats <?php echo $courseToShow ?></h1>
<?php

if($queryKey=="challenge" && $tabRequest!=0){
	$results=$tool-> buildList($tabRequest);
		?>
		<table><tr><td>
	<table class="principale">
			<tr>
				<th colspan="5"><h2>CHALLENGE</h2></th>
			</tr>
			<tr>
				<th>Position</th>
				<th>Nom</th>
				<th>Prénom</th>
				<th>Challenge points</th>
				<th>Détail</th>
			</tr>
		
			<?php
			if(sizeof($results)>0){
			
			$cptF=1;
			for($i=0;$i<sizeof($results);$i++){?>
			<tr class="list">
				<td class="listing"><?php echo($i+1); ?></td>
				<td class="listing"><?php echo($results[$i]->getNom()); ?></td>
				<td class="listing" align="center"><?php echo($results[$i]->getPrenom()); ?></td>
				<td class="listing" align="center"><?php echo($results[$i]->getChallengeTotal()); ?></td>
				<td class="listing" align="left"><?php echo($results[$i]->info); ?></td>
			</tr>
		
			<?php }
			} ?>
		</table>
		</td></tr>
		</table>
	<?php
}else{
	if($tabRequest!=0){
		$tool->listQuery($tabRequest,"Résultats",$courseToShow);
	}
}
$obj_utils->close();

?>
